package com.myshiro.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.myshiro.pojo.SysUser;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

public interface SysUserMapper extends BaseMapper<SysUser> {
    @Select("SELECT u.*,r.role_name" +
            " FROM `sys_user` u" +
            " inner join sys_role r" +
            " on u.usr_role_id =r.role_id" +
            " where u.usr_name=#{usrName}")
    @Results(value = {
            @Result(property = "roleName",column = "role_name")
    })
    public SysUser getByUsrNameSysUser(String usrName);

    @Select("SELECT u.usr_id,u.usr_name,u.usr_password,u.usr_role_id,u.usr_flag,r.role_name" +
            " FROM `sys_user` u" +
            " inner join sys_role r" +
            " on u.usr_role_id =r.role_id" +
            " where u.usr_name=#{usrName}")
    @Results(value = {
            @Result(column = "usr_role_id" //当做查询条件
                    ,property = "role"      //查询结果
                    // usr_role_id ->SysRoleMapper.selectById(usr_role_id)  子查询
                    ,one = @One(select = "com.myshiro.dao.SysRoleMapper.selectById")
            )
    })
    public SysUser getByUsrNameSysUserAndRole(String usrName);
}
